// pages/poster/poster.js
var $=require('../util/commit.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
      selectLIndex:0,
      selectRIndex:-1,
      listData:[],
      listDetailData:[],
      selectTypeId:'',
      TopImage:'',
      pic_id:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
    that.loadData();

  },
  // 加载活动
  loadData:function(){
    let that = this;
    $.POST({
      url:'caSPC',
      data:{

      }
    },function(e){
      console.log(e.data[0].poster);
      that.setData({
        listData:e.data,
        selectTypeId:e.data[0].id
      });
      that.loadPosterData();
    },function(e){

    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // selectLItem
  selectLItem:function(e){
    let that=this;
    that.setData({
      selectLIndex:e.currentTarget.dataset.index,
      selectTypeId: e.currentTarget.dataset.id,
    });
    that.loadPosterData();
  },
  // 加载海报图片
  loadPosterData:function(e){
    let that=this;
    $.POST({
      url:'caSPCP',
      data:{
        pcid: that.data.selectTypeId
      }
    },function(e){
        that.setData({
          listDetailData:e.data,
          selectRIndex:-1,
        })
    },function(e){

    })
  },
  // selectImg
  selectImg:function(e){
    let that = this;
    console.log(e);
    if (that.data.selectRIndex != e.currentTarget.dataset.index){
      that.setData({
        selectRIndex: e.currentTarget.dataset.index,
    
      })
      let pages = getCurrentPages();
      let prevPage = pages[pages.length - 2];
      console.log(e.currentTarget.dataset.url);
      prevPage.setData({
        TopImageHide: false,
        TopImage: e.currentTarget.dataset.url,
        pic_id: e.currentTarget.dataset.picid,
      })
    }else{
      that.setData({
        selectRIndex: -1,
      })
    }
   
  },
  // sureSelect
  sureSelect:function(e){
    let pages=getCurrentPages();
    let prevPage=pages[pages.length-2];
    console.log(e.currentTarget.dataset.url);
    prevPage.setData({
      TopImageHide: false,
      TopImage: e.currentTarget.dataset.url,
      pic_id: e.currentTarget.dataset.picid,
    })
     wx.navigateBack();
   
  }
})